function sendsms(){
	var receivers=$("#receivers").val();
	$("#confirm").attr("disabled",true).css("background","#ccc").unbind("click").css("cursor","none");
	setTimeout(function(){
		$("#confirm").attr("disabled",false).css("background","url(../images/add_member.jpg) repeat-x 0 0").bind("click",sendsms).css("cursor","pointer");
	},5000);
	if(receivers==""){
		alert("请输入收件人手机号");
		return;
	}
	receivers=receivers.replace("；",";");
	receivers=receivers.replace("：",":");
	if(receivers.length<11||(receivers.length>11&&receivers.indexOf(";")<0)){
		alert("输入用户和手机号格式不正确");
		return;
	}
	/*var receiverlist=new Array();
	if(receivers.length==11){
		if(isPhoneNumber(receivers)){
			receiverlist[0]=receivers;
		}
	}else{
		var phonelist=receivers.split(",");
		var flag=true;
		for(var i=0;phonelist.length;i++){
			if(!isPhoneNumber(phonelist[i])){
				flag=false;
				break;
			}
			receivers[i]=phonelist[i];
		}
		if(!flag){
			alert("输入手机号码有误");
			return;
		}
	}*/
	var content=$("#content").val();
	if(content==""){
		alert("短信内容不能为空");
		return;
	}
	var imageCode = $('#imageCode').val();
	 if(!/\d{4}/.test(imageCode)){
		alert('图形验证码必须是4位数字！');
		$('#imageCode').focus();
		return false;
	 }
	$.ajax({
		url : contextPath+'admin/sms/batchsend',
		data :{
			receivers : receivers,
			content : content,
			imageCode :imageCode
		},
		type :"post",
		async : false,
		success : function(data){
			alert(data.msgDesc);
		}
	});
}

function excelShow(){
	$(".add_members_cont_box").hide();
	$("#excelAddBox").height(190);
	$("#errorContent").empty();
	$("#excelAddBox").show();
}

function batchadd() {
	$("#errorContent").empty();
	var domId ="userFile"; 
	var file_name = $('#'+domId).val();
	var extStart=file_name.lastIndexOf("."); 
	var ext=file_name.substring(extStart,file_name.length).toUpperCase(); 
	if (file_name == null || file_name.length < 1) {
		//top.uppShow('必须选择一个文件才能上传');
		return false;
	}
//	if(ext!=".XLS"&&ext!=".XLSX"){ 
//		alert("文件格式不正确！");
//		$("#userFile").focus();
//		return false; 
//	}else{
		$.ajaxFileUpload({
			url : contextPath+ 'admin/sms/readfile',
			secureuri : false,
			fileElementId : domId,
			data : [ $('#' + domId).attr('name') ],
			dataType : 'json',
			success : function(data, status) {
				if (data.opResult == "0" || data.opResult == "2") {
//					if(list!=null){
						$("#receivers").val(data.smsStr);
						var error = data.errorlist;
						for(var i=0;i<error.length;i++){
							var div = '<div class="add_members_cont">';
							div += '<ul class="add_members_cont_ul">';
							div += '<li class="number" style="width: 6%">'+(i+1)+'</li>';
							div += '<li class="username" style="width: 20%">'+(error[i][0]==null?"":error[i][0])+'</li>';
							div += '<li class="operation" style="width: 20%">'+(error[i][1]==null?"":error[i][1])+'</li>';
							div += '<li class="tel_num" style="width: 24%">'+(error[i][2]==null?"":error[i][2])+'</li>';
							div += '<li class="checked" style="width: 30%;border-right:none;">'+(error[i][3]==null?"":error[i][3])+'</li>';
							div += '</ul>';
							div += '</div>';
							$("#errorContent").append(div);
						}
						$(".add_members_cont_box").show();
						$("#excelAddBox").height(480);
						$("#dh").height(442);
				}
			},
			error : function(data, status, e) {
				alert("error");
			}
		});
//	}
}

function isPhoneNumber(text){
	var exp=/^1[0-9]{10}$/;
	return exp.test(text);
}

function reset(){
	$("#content").val("");
	$("#receivers").val("");
	$('#imageCode').val("");
	changeImageCode();
}
/**
 * 刷新图形验证码
 */
function changeImageCode(){
	$('#imageCodeImg').attr('src',$('#imageCodeImg').attr('src') + '?timestamp=' + new Date().getTime());
}